package com.informit.jlayer;

// Import the JLayer classes
import javazoom.jl.player.*;

// Import the Java classes
import java.io.*;

/**
 *
 * @author shaines
 */
public class MP3Player {

 private Player player;
 private InputStream is;
 
 /** Creates a new instance of MP3Player */
 public MP3Player( String filename ) 
 {
  try
  {
   // Create an InputStream to the file
   is = new FileInputStream( filename );
  }
  catch( Exception e )
  {
   e.printStackTrace();
  }
 }
 
 public void play()
 {
  try
  {
   player = new Player( is );
   PlayerThread pt = new PlayerThread();
   pt.start();
   while( !player.isComplete() )
   {
    int position = player.getPosition();
    System.out.println( "Position: " + position );
    try
    {
     Thread.sleep( 1000 );
    }
    catch( Exception ee )
    {
     ee.printStackTrace();
    }
   }
  }
  catch( Exception e )
  {
   e.printStackTrace();
  }
 }
 
 class PlayerThread extends Thread
 {
  public void run()
  {
   try
   {
    player.play();
   }
   catch( Exception e )
   {
    e.printStackTrace();
   }
  }
 }
 
    
    public static void main( String[] args )
    {
	try{
	    if( args.length == 0 )
		{
		    System.out.println( "Usage: MP3Player <filename>" );
		    System.exit( 0 );
		}
	    
	    MP3Player mp3Player = new MP3Player( args[ 0 ] );
	    mp3Player.play();
	}
	catch(Exception e){}
    }
}